package com.zhp.web; /**
 * @Author Lone Ranger
 */

import com.alibaba.fastjson.JSON;
import com.zhp.common.R;
import com.zhp.service.OrderService;
import com.zhp.service.impl.OrderServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/checkDate")
public class CheckOrderServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 预约日期
        String odate = request.getParameter("odate");
        // 医生id
        String edid = request.getParameter("edid");
        // 预约时间
        String sjdid = request.getParameter("sjdid");

        OrderService orderService = new OrderServiceImpl();
        boolean b = orderService.checkData(odate, edid, sjdid);

        PrintWriter writer = response.getWriter();

        String s = "";
        if (b) {
            R<String> r = new R<>();
            r.setCode(200);
            s = JSON.toJSONString(r);
        } else {
            R<String> r = new R<>();
            r.setCode(500);
            s = JSON.toJSONString(r);
        }
        writer.write(s);

    }
}
